//
//  Service+DiaryBook.m
//  huimei
//
//  Created by fengyn on 16/1/23.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

#import "Service+DiaryBook.h"

@implementation ServiceManager(DiaryBook)

///创建日记本
+ (void)createDiaryBookWithInfo:(NSDictionary *)infoDic success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = @"/diarybook";
    NSDictionary *parameterDict=infoDic;
    [NetworkClient postRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///删除日记本
+ (void)deleteDiaryBookWithId:(NSString *)diaryBookId success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = [NSString stringWithFormat:@"/diarybook/%@",diaryBookId];
    NSDictionary *parameterDict=nil;
    [NetworkClient deleteRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}
///删除日记
+ (void)deleteDiaryWithId:(NSString *)diaryId success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString * path = [NSString stringWithFormat:@"/content/%@",diaryId];
    NSDictionary * parameterDict = nil;
    [NetworkClient deleteRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];

}
///分页查询自己的日记本
+ (void)getMyDiaryBooksWithPageIndex:(NSUInteger)pageIndex success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = @"/diarybook/page";
    const int countPer=20;
    NSDictionary *parameterDict=@{@"start":@(pageIndex*countPer),
                                  @"length":@(countPer)};
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///查询日记本详情
+ (void)getDiaryBookInfoWithId:(NSString *)diaryBookId success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = [NSString stringWithFormat:@"/diarybook/%@",diaryBookId];
    NSDictionary *parameterDict=nil;
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}
@end

